<script>
	var utils = require('@/utils/tools.js');
	export default {
		onLaunch: function(option) {
			console.log('App onLaunch')
		},
		onShow: function() {
			let that = this
				// let provider = that.loginProvider;
			uni.getProvider({
				service: 'oauth',
				success: function (pro) {
					uni.login({
					  provider: pro.provider[0],
					  success: function(res) {
						that.$u.post('/login', {
						  code: res.code,
						  provider: pro.provider[0]
						}, '').then(res => {
						  that.$u.vuex('vuex_new_user', res.new);
						  if (!res.new) {
							that.$u.vuex('vuex_token', res.token);
							that.$u.vuex('vuex_user', {
							  'nickname': res.nickname,
							  'openid': res.openid
							});
							uni.setStorage({
							  key: 'userInfo',
							  data: res,
							  success: function() {
								// that.$emit('authConfirm', true);
								// that.$u.vuex('vuex_token', res.token);
							  }
							});
						  }
						}).catch(err => {
						  console.log(err, "err")
						  uni.showToast({
							title: "远端服务不可用~",
							icon: "none"
						  });
						});
					  },
					  fail(err) {
						console.log('login:', err);
					  }
					});
				}
			});
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	@import "uview-ui/index.scss";
	@import "utils/animate.min.css";
	@import "static/base.scss";
</style>
